﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nBayes;
using MailClient.Properties;
using MailClient.Handlers;
using MailClient.Data;
using MailClient;
using MailClient.Data.IndexTables;

namespace MailClient.Commands
{
    class Training : ICommand, IDisposable
    {
        #region Private
        private MailMessage _msg;
        private Handlers.designator _designator;
        #endregion

        public Training(string[] parameter)
        { Parameter = parameter; }

        public Handlers.designator Designator
        {
            get { return _designator; }
            set { _designator = Designator; }
        }

        public MailMessage MsgReply
        {
            get { return _msg; }
        }

        public void Dispose() { }

        public bool CommitData() { return false; }

        public bool Command(Job job)
        {
            string query = Parameter[0];
            query = query.Trim();
            query = query.Word(0, " ");
            query = query.Trim();
            job.TestString = job.TestString.Remove(0, query.Length) + " " + job.MessageBody;

            switch (query)
            {
                default:
                    return false;
                case "spam":
                    // train spam index
                    SpamIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "notspam":
                    // train not spam index
                    NotSpamIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "merch":
                    // train merch index
                    MerchIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "shell":
                    // train shell index
                    ShellIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "geotech":
                    // train geo tech index
                    GeoIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "fuelstudy":
                    // train fuel study index
                    FuelIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "brc":
                    // train brc index
                    BrandIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "cityapproval":
                    // train city index
                   CityIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "waterreport":
                    // train water report index
                    WaterIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "designcivil":
                    // train design civil index
                    CivilIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "person":
                    // train person index
                    PersonIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
                case "store":
                    // train store index
                    StoreIndex.Index.Add(Entry.FromString(job.TestString));
                    break;
            }
            _msg = new MailMessage();
            _msg.Subject = "Re: Training";
            _msg.Body = "That was a " + Parameter[0] + " and I entered it in.";
            var to = new System.Net.Mail.MailAddress("bcrawford@rhaaia.com");
            var from = new System.Net.Mail.MailAddress("rha@rhaaia.com", "RHA Email");
            _msg.To.Add(to);
            _msg.Sender = from;
            return true;
        }
        
        public string[] Parameter { get; set; }
    }
}
